<#include "/custom.include">
<#include "/java_copyright.include">
<#assign className = table.className>   
<#assign classNameLower = className?uncap_first>
<#assign actionExtension = "do">
package ${basepackage}.action.${moduleNameLower};

import com.seeingtv.controller.base.BaseController;
import com.seeingtv.vo.GridData;
import com.seeingtv.vo.PageData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import ${basepackage}.model.${className};
import ${basepackage}.service.${className}Manager;

@Controller
@RequestMapping("/${table.classNameLowerCase}")
public class ${className}Controller extends extends BaseController {
    @Resource
    ${className}Service ${table.classNameLowerCase}Service;

	/**
	 * @since  list 页面定向
	 */
	@RequestMapping("/list")
	public ModelAndView toList(){
		ModelAndView mv = getModelAndView();
		//页面路径
		mv.setViewName("${table.classNameLowerCase}/list");
		return mv;
	}

	/**
	 * @since RequestMapping 方法级别，必须有
	 */
	@RequestMapping("/getlist")
	@ResponseBody
	public GridData<${className}> getList(){
		//返回表格数据
		GridData<${className}> gridData = getGridData();
		//页面传值
		PageData pd = getPageData();
		//具体业务逻辑写在service层
		gridData = ${table.classNameLowerCase}Service.getPageByCond(pd);

		return gridData;
	}

	@RequestMapping("/savedetail")
	public ModelAndView toSaveDetail() {
		ModelAndView mv = getModelAndView();
		//详情页提交方法名称
		mv.addObject("method","save");
		//页面路径
		mv.setViewName("sysadmin/detail");
		return mv;
	}

	@RequestMapping("/editdetail")
	public ModelAndView toEditDetail(@RequestParam("id") Integer id) {
		ModelAndView mv = getModelAndView();
		//详情数据
		PageData pd = ${table.classNameLowerCase}Service.getOneSysadminById(id);
		mv.addObject("pd",pd);
		//部门列表
		mv.addObject("deptList","");
		//详情页提交方法名称
		mv.addObject("method","edit");
		//页面路径
		mv.setViewName("sysadmin/detail");
		return mv;
	}

	@RequestMapping("/viewdetail")
	public ModelAndView toView(@RequestParam("id") Integer id) {
		ModelAndView mv = getModelAndView();
		PageData pd  = ${table.classNameLowerCase}Service.getOneSysadminById(id);
		mv.addObject("pd",pd);
		//路径
		mv.setViewName("sysadmin/view");
		return mv;
	}

	@RequestMapping("save")
	@ResponseBody
	public GridData<${className}> save() {
		GridData<${className}> gridData = getGridData();
		PageData pd = getPageData();
		if (pd != null) {
		if (pd.getString("status") == null) {
		pd.put("status",0);
		}
		gridData = ${table.classNameLowerCase}Service.save(pd);
		}
		return gridData;
	}

	/**
	 * @since 获取页面参数，若传值是form表单中的元素对象，可采用@ModelAttribute Sysadmin sysadmin方式获取（指定对象）
	 * 也可以才PageData pd = getPageData() 获取页面元素值(map存放)
	 * */
	@RequestMapping("edit")
	@ResponseBody
	public GridData<${className}> edit(@ModelAttribute ${className} ${table.classNameLowerCase}) {
		GridData<${className}> gridData = getGridData();
		PageData pd = getPageData();
		if (pd != null) {
			gridData = ${table.classNameLowerCase}Service.update(${table.classNameLowerCase});
		}
		return gridData;
	}

	@RequestMapping("/delete")
	@ResponseBody
	public GridData<${className}> toDelete(@RequestParam("ids") String ids) {
		GridData<${className}> gridData = getGridData();
		gridData = ${table.classNameLowerCase}Service.deleteByIds(ids);
		return gridData;
	}
}

